clear all
clear matrix
version 13
capture log close
set matsize 11000
set more off, permanently

*-------------------------------------------------------------------------------
* Options	
*-------------------------------------------------------------------------------
global date = "2306"
global niter = 15

global stub 	 = "/Volumes/Transcend/AWFP/ThirdChapter_revision"
global main		 = "$stub/data"
global inputcali = "$stub/data/CalibrationInput"	
global outputcali= "$stub/data/CalibrationOutput"	
global data_proc = "$stub/data"
global graphs    = "$stub/graphs"	
global tables    = "$stub/tables"
global do        = "$stub/do"
global excel     = "$stub/excel"	
global orig      = "$stub/orig"

cd "$main"
********************************************************************************
local year = "2020"
local tempdir = "${outputcali}/Intervals_"+"$date"+"`year'/"

forv i = 1(1)$niter {
forv n = 1(1)$N {
local filename = "`tempdir'"+ "interval"+"`n'"+"trial"+"`i'"+".csv"
import delimited using "`filename'", clear
compress
gen idtime = _n
gen aux = idtime/4
gen quarter = 4 if int(aux) == aux
replace quarter = 1 if mod(aux,1) == .25
replace quarter = 2 if mod(aux,1) == .5
replace quarter = 3 if mod(aux,1) == .75
gen year = 1990 if idtime == 1
replace year = 1990+int(aux) if mod(aux,1) == 0.25
replace year = year[_n-1] if year==.
gen eventdate=yq(year,quarter)
format eventdate %tq
keep v* eventdate
reshape long v, i(eventdate) j(s)
sum s
global S = `r(max)'
reshape wide v, i(eventdate) j(s)
gen amr = `n'
if `n'==1{
save "${outputcali}/Heiko_${date}`year'/interval`i'_${date}.dta", replace
}
else{
append using  "${outputcali}/Heiko_${date}`year'/interval`i'_${date}.dta"
save  "${outputcali}/Heiko_${date}`year'/interval`i'_${date}.dta", replace
}
}
}
********************************************************************************

